package com.topnav.mc.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.topnav.mc.admin.dao.mapper.FenceAlarmMapper;
import com.topnav.mc.admin.entity.Fence;
import com.topnav.mc.admin.entity.FenceAlarm;
import com.topnav.mc.admin.entity.bean.DeviceAlarmBean;
import com.topnav.mc.admin.entity.bean.FenceAlarmBean;
import com.topnav.mc.admin.entity.enums.DeviceAlarmCate;
import com.topnav.mc.admin.entity.enums.FenceAlarmType;
import com.topnav.mc.admin.entity.param.DeviceAlarmParam;
import com.topnav.mc.admin.entity.param.FenceAlarmParam;
import com.topnav.mc.admin.service.IFenceAlarmService;
import com.topnav.mc.base.mc.McServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

/**
 * @Author: kenny
 * @Date: 2023/11/13 11:31
 */
@Service
public class FenceAlarmServiceImpl extends McServiceImpl<FenceAlarmMapper, FenceAlarm, FenceAlarmBean, FenceAlarmParam>
        implements   IFenceAlarmService {

    @Override
    public boolean beforeSave(FenceAlarm entity){
        entity.setCreateTime(new Date());
        entity.setUpdateTime(new Date());
        return true;
    }

    @Override
    public  boolean beforeUpdate(FenceAlarm entity){
        entity.setUpdateTime(new Date());
        return true;
    }
    @Override
    public  boolean beforeDelete(FenceAlarm entity){
        return true;
    }
/*
    @Override
    public Page<FenceAlarmBean> pageInfo(Page<FenceAlarmParam> page , Wrapper<FenceAlarmParam> queryWrapper){
        Page<FenceAlarmBean> page1 = super.pageInfo(page,queryWrapper);
        if (!CollectionUtils.isEmpty(page1.getRecords())){
            this.getPropertyForDescs(page1.getRecords());
        }
        return page1;
    }

    @Override
    public List<FenceAlarmBean> listInfo(Wrapper<FenceAlarmParam> queryWrapper){
        List<FenceAlarmBean> list = super.listInfo(queryWrapper);
        if (!CollectionUtils.isEmpty(list)){
            this.getPropertyForDescs(list);
        }
        return list;
    }

    @Override
    public FenceAlarmBean getOneInfo(Wrapper<FenceAlarmParam> queryWrapper, boolean throwEx){
        FenceAlarmBean fenceAlarmBean = super.getOneInfo(queryWrapper,throwEx);
        if (fenceAlarmBean != null){
            this.getPropertyForDesc(fenceAlarmBean);
        }
        return fenceAlarmBean;
    }

    *//**
     * 结果值报警类型描述
     * @param fenceAlarmBeans
     *//*
    private void getPropertyForDescs(List<FenceAlarmBean> fenceAlarmBeans){
        //报警类型
        for (FenceAlarmBean fenceAlarmBean : fenceAlarmBeans) {
            this.getPropertyForDesc(fenceAlarmBean);
        }
    }

    *//**
     * 结果值设备类型描述
     * @param fenceAlarmBean
     *//*
    private void getPropertyForDesc(FenceAlarmBean fenceAlarmBean){
        //报警类型
        for (FenceAlarmType fenceAlarmType : FenceAlarmType.values()) {
            if (fenceAlarmBean.getAlarmType() == fenceAlarmType.getCode()){
                fenceAlarmBean.setFenceAlarmTypeDesc(fenceAlarmType.getDesc());
                break;
            }
        }
    }*/
}
